package ${modulePackage}.utils;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

public class FreemarkerUtils {

    static final Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);

    public static String process(String template, Object model) {

        if (StringUtils.isBlank(template)) {
            return "";
        }

        try {
            StringWriter out = new StringWriter();
            new Template("template", new StringReader(template), configuration).process(model, out);
            return out.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        }
        return "";
    }
}